# 1-导包
from flask import Flask,request

# 2-创建对象
app = Flask(__name__)
app.config['JSON_AS_ASCII'] = False  # 中文显示正常（jmeter还需要修改配置文件才行）
# https://blog.csdn.net/Moonlight_16/article/details/121038111

# 3-定义一个测试方法，执行逻辑判断，返回响应结果
@app.route('/mock/login',methods=["post"])  # 设置接口的请求方法和路径
def mock_login():
    # 获取接口请求的参数，模拟登录接口：username+password
    username = request.json.get("username")
    password = request.json.get("password")
    # 进行逻辑判断，返回响应结果
    if username == "admin" and password == "123456":  # 登录成功
        return { "msg": "登录成功", "code": 200, "token": "1235646745sadfasdf6"}
    else:  # 登录失败,状态码设置为666
        return { "msg": "登录失败", "code": 666, "token": "没有洛"},666

# 4-启动服务，设置端口和开启调试模式
app.run(port=666,debug=True)